import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () => import('../views/Home.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/detail/:iid',
    name: 'detail',
    component: () => import('../views/detail.vue')
  },
  {
    path: '/Me',
    name: 'Me',
    component: () => import('../views/me/Me.vue')
  },
  {
    path: '/Category',
    name: 'Category',
    component: () => import('../views/category/Category.vue')
  },
  {
    path: '/Cart',
    name: 'Cart',
    component: () => import('../views/cart/Cart.vue')
  }
]

const router = new VueRouter({
  //mode: 'history',
  routes
})

// 重写路由push方法,阻止重复点击报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

// 重写路由replace方法,阻止重复点击报错
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};


export default router
